﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace App7._9
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();

            NameCard card1 = new NameCard();
            card1.Name = "Wenwen Che";
            card1.Address = "Li Hua Street";

            FrameworkElementFactory nameBlock = new FrameworkElementFactory(typeof(TextBlock));
            Binding nameBinding = new Binding("Name");
            nameBlock.SetBinding(TextBlock.TextProperty, nameBinding);

            FrameworkElementFactory addressBlock = new FrameworkElementFactory(typeof(TextBlock));
            Binding addressBinding = new Binding("Address");
            addressBlock.SetBinding(TextBlock.TextProperty, addressBinding);

            FrameworkElementFactory stackPanel = new FrameworkElementFactory(typeof(StackPanel));
            stackPanel.AppendChild(nameBlock);
            stackPanel.AppendChild(addressBlock);

            DataTemplate template = new DataTemplate();
            template.VisualTree = stackPanel;

            list.ItemTemplate = template;
            list.Items.Add(card1);
        }
    }

    class NameCard : Object
    {
        string _name;
        string _address;

        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        public string Address
        {
            get { return _address; }
            set { _address = value; }
        }
    }
}
